package controller;

import init_tests.NxtPreStartTests;
import lejos.nxt.Button;
import lejos.nxt.Sound;
import logic.NxtLogic;

public class NxtController {

	// vars
	private NxtLogic nxtLogic;

	// constructors
	public NxtController(NxtLogic logic) {
		super();
		this.nxtLogic = logic;
		init();
	}

	// methods
	public void init() {
		// wait for button press to start
		System.out.println("press orange button to start!");
		Button.waitForAnyPress();
		Sound.systemSound(true, 2);
		System.out.println("starting...!");

		// check if specified sensors are connected

		NxtPreStartTests preStartTests = new NxtPreStartTests();
		try {
			preStartTests.testAll();
		} catch (IllegalStateException ex) {
			NxtSafeState.getInstance().putInSafeState();
		}

		NxtSafeState.init = false;
		// if there is no error start with the main program
		nxtLogic.run();
	}
}
